package com.theeviljames.renderer;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class GraphRenderer extends JFrame {

	private static final int defaultWidth = 640;
	private static final int defaultHeight = 640;
	
	
	public GraphRenderer() {
		super("EvilMath");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(defaultWidth,defaultHeight);
		setVisible(true);
		setLayout(new BorderLayout());
		
		RenderPanel panel = new RenderPanel(defaultWidth, 3*(defaultHeight/4), this);
		
		JTextField expression = new JTextField(20);
		
		JButton render = new JButton("Draw!");
		render.addMouseListener(new MouseListener(){
			public void mouseClicked(MouseEvent arg0) {
				
			}
			public void mouseEntered(MouseEvent arg0) {}
			public void mouseExited(MouseEvent arg0) {}
			public void mousePressed(MouseEvent arg0) {}
			public void mouseReleased(MouseEvent arg0) {}
		});
	}
	
	public class RenderPanel extends JPanel{
		
		private BufferedImage bi;
		private WritableRaster wr;
		private JFrame parent;
		
		public RenderPanel(int x, int y, JFrame parent) {
			bi = new BufferedImage(x,y,BufferedImage.TYPE_INT_RGB);
			wr = bi.getRaster();
			this.parent = parent;
			setBackground(Color.WHITE);
		}
		
		public void drawPixel(int x, int y, Color color){
			wr.setPixel(x, y, color.getColorComponents(null));
		}
		
		@Override
		public void paint(Graphics g) {
			g.drawImage(bi, 0, 0, null);
		}
	}
}
